package controle;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JOptionPane;

import abstraction.Cours;

/** controleur appelé lors de la suppression d'un étudiant
 * 
 * @author PICOSSON
 *
 */
	public class ControlJButtonDeleteEtudiant implements  Observer, ActionListener {
		private Cours modele;
		private Frame parent;
		private JButton button;

		public ControlJButtonDeleteEtudiant(Frame parent, Cours modele, JButton button) {
			this.modele = modele;
			this.parent = parent;
			this.button = button;
		
		}
	
		public void actionPerformed(ActionEvent e) {
			int choix = JOptionPane.showConfirmDialog(parent,
					"Confirmez-vous la suppression ?", "Confirmation",
					JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
			if (choix == JOptionPane.YES_OPTION)
				try {
					this.modele.deleteEtudiant(this.modele.getEtudiantCourant());
				} catch (SQLException e1) {
					JOptionPane.showMessageDialog(parent, "On ne peut pas!",
							"Erreur!", JOptionPane.ERROR_MESSAGE);
				}			
		}
		
		public void update(Observable o, Object message) {
			Integer iMessage = (Integer) message;
			if (iMessage == Cours.CHANGEMENT_ETUDIANT_COURANT) {
				if (modele.getEtudiantCourant() == null){
					button.setEnabled(false);
				}
				else
				{
					button.setEnabled(true);
				}
			}
		}
}

